package com.yzjs.wx.controller;

import com.yzjs.base.PayResponse;
import com.yzjs.base.RefundResponse;
import com.yzjs.config.WxPayConfig;
import com.yzjs.enumeration.BestPayTypeEnum;
import com.yzjs.wx.service.PayService;
import com.yzjs.wx.service.ReturnService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("refund")
@Slf4j
public class RefundController {


    @Autowired
    private ReturnService returnService;

    @Autowired
    private WxPayConfig wxPayConfig;


    @GetMapping("create")
    public Map create(
                     @RequestParam("openId") String openId ,
                     @RequestParam("orderNo") String orderNo,
                     @RequestParam("amount") BigDecimal orderAmout ){

        RefundResponse refundResponse   = returnService.create(openId,orderNo, orderAmout , BestPayTypeEnum.WXPAY_NATIVE);
        Map map = new HashMap<>();
        map.put("outRefundNo" , refundResponse.getOutRefundNo());
        map.put("orderNo",orderNo);
        map.put("returnUrl",wxPayConfig.getReturnUrl());
        return map;
    }
}
